import request, { type ListQuery, type ListResponse } from "@/utils/request";
import { type UserProfileType } from "../user/profile";

const THIRD_APP_BASE_URL = "/api/internal/ThirdPartSystem";

export interface ThirdAppListQuery extends ListQuery {}

export interface ThirdAppType {
  id: number;
  user: UserProfileType;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  name: string;
  appid: string;
  secret_key: string;
  aes_key: string;
  server_addr: string;
  enable_whitelist: boolean;
  whitelist: string;
}

export interface ThirdAppFormType {
  id?: number;
  user: number | string;
  name: string;
  appid: string;
  secret_key: string;
  aes_key: string;
  server_addr: string;
  enable_whitelist: boolean;
  whitelist: string;
}

export const getThirdAppList = (params?: ThirdAppListQuery) => {
  return request.get<any, ListResponse<ThirdAppType>>(`${THIRD_APP_BASE_URL}/`, {
    params,
  });
};

export const addThirdApp = (data: Partial<ThirdAppFormType>) => {
  return request.post(`${THIRD_APP_BASE_URL}/`, data);
};

export const updateThirdApp = (data: Partial<ThirdAppFormType>) => {
  return request.put(`${THIRD_APP_BASE_URL}/${data.id}/`, data);
};

export const deleteThirdApp = (id: number) => {
  return request.delete(`${THIRD_APP_BASE_URL}/${id}/`);
};
